package com.xuxin.pda.model;

import com.blankj.utilcode.util.LogUtils;
import com.xuxin.pda.bean.LoginBean;
import com.xuxin.pda.bean.TrashSummaryBean;
import com.xuxin.pda.contract.TrashSummaryContract;
import com.xuxin.pda.network.Retrofit;
import com.xuxin.pda.network.RetrofitApi;
import com.xuxin.pda.presenter.TrashSummaryPresenter;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.observers.DisposableObserver;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
 * Created by xu_xin
 * Created on 2021/2/7 0007
 */
public class TrashSummaryModel implements TrashSummaryContract.Model {
    @Override
    public void getTrashSummary(TrashSummaryPresenter presenter, String year, String month, String day, String In_MOrD) {
        Retrofit.getInstance().createReq(RetrofitApi.class)
                .getTrashSummary(year,month,day,In_MOrD)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new DisposableObserver<TrashSummaryBean>() {
                    @Override
                    public void onNext(@NonNull TrashSummaryBean trashSummaryBean) {
                        if (trashSummaryBean.isSuccess()) {
                            LogUtils.e("xxxx");
                            presenter.onSuccess(trashSummaryBean);
                        } else {
                            LogUtils.e("sss");
                            presenter.onError(trashSummaryBean);
                        }
                    }

                    @Override
                    public void onError(@NonNull Throwable e) {
                        presenter.onError(null);
                    }

                    @Override
                    public void onComplete() {
                        presenter.onComplete();
                    }
                });
    }
}
